﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AMS.DD35.DbLoader.Views;
using AMS.DD35.DbLoader.Models;
using System.Windows.Forms;

namespace AMS.DD35.DbLoader.Controllers
{
    class ClassController : EditorControllerBase, IClassController
    {
        private IClassModel _model;

        public ClassController()
        {
        }

        #region Initialization Methods
        protected override void InitializeFields()
        {
            // tightly couple here per MVC
            _model = new ClassModel();
            _browser = new BrowserDialog(this);
            _browser.NewButtonText = "New Class";
            _browser.Text = "Class Browser";

            IEnumerable<object> classes = _model.GetClasses();
            _browser.Populate(classes);
        }

        protected override void LoadEditor()
        {
            // TODO: prep class editor to be Editor
            // Get Class data
            // Load class data into ClassEditor
            ClassEditor classEditor = new ClassEditor(this);
            classEditor.PopulateClassId("-1");
            classEditor.EnableClassId = false;

            _editor = classEditor;
        }

        protected override void PrepNewEditor()
        {
            // prep class editor to be New
            ClassEditor classEditor = new ClassEditor(this);
            classEditor.PopulateClassId("new");
            classEditor.EnableClassId = false;

            _editor = classEditor;
        }
        #endregion

        // note: lots of tight coupling follows; candidates for DI or IoCC

        // duplicating code (this and any Controller that spawns windows)
        // TODO: consider a SpawnerBase and I_Spawner interfaces

        public void BrowseSources()
        {
            SourceController sourceController = new SourceController();
            sourceController.Execute();
        }

        public void BrowseFeats()
        {
            FeatController featController = new FeatController();
            featController.Execute();
        }

        public void BrowseClassFeatures()
        {
            ClassFeatureController classFeatureController = new ClassFeatureController();
            classFeatureController.Execute();
        }

        public void BrowseWeapons()
        {
            WeaponController weaponController = new WeaponController();
            weaponController.Execute();
        }

        public void BrowseArmors()
        {
            ArmorController armorController = new ArmorController();
            armorController.Execute();
        }

        public void SpawnShieldEditor()
        {
            ShieldController shieldController = new ShieldController();
            shieldController.Execute();
        }

        public void SpawnSkillEditor()
        {
            SkillController skillController = new SkillController();
            skillController.Execute();
        }

        public void SpawnSpellsPerDayDialog()
        {
            MessageBox.Show("Not Yet Implemented!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            // TODO: Create a SpellsPerDay data object
            // TODO: Spawn a SpellsPerDay dialog
            // Depending on DialogResult, get SpellsPerDay data object and set it to this class for update
        }

        public void SpawnSpellsKnownDialog()
        {
            MessageBox.Show("Not Yet Implemented!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            // TODO: Create a SpellsKnown data object
            // TODO: Spawn a SpellsKnown dialog
            // Depending on DialogResult, get SpellsKnown data object and set it to this class for update
        }
    }
}
